var product = function () {
	
	var sort = function() {
	      
	  	  $('#sort').click(function() {
	  		var arr = {};		
	  		$(".sortText").each(function() {
	  			if($(this).val()){
	  				arr[$(this).attr("id")] = $(this).val();
	  			}
	  			
	 		 });
	  		
	  	 
			$.ajax({ 
			type: "post", 
			url: "/product/sort/put", //服务端处理程序 
			data: { arr:arr} , //id:新的排列对应的ID 
			error:function (msg) {
				alert(msg.responseText);

			},
			success: function(res) { 
				res = JSON.parse(res);
				if( res.status == '1' ){
					bootbox.dialog({
			                    message: "排序成功！",
			                    title: "",
			                    buttons: {
			                      success: {
			                        label: "OK",
			                        className: "green",
			                        callback: function() {
				        	 			window.location.href = '/product/lists/get';
			                        }
			                      }
			                    }
			                }); 	
					
  			}else{
  				bootbox.dialog({
			                    message: "排序失败！",
			                    title: "",
			                    buttons: {
			                      success: {
			                        label: "OK",
			                        className: "green",
			                        callback: function() {
				        	 			window.location.href = '/product/lists/get';
			                        }
			                      }
			                    }
			                }); 	
      		}              			
  
		 	} 
			});	
	  	});

	}

    return {
        //main function to initiate the module

        init: function () {
    		sort();
        	$('#btnNewOperator').click(function(){
        		window.location.href = '/product/newresource/get';
        	});
        	
        },
        modify: function( id ){
        	window.location.href = '/product/modifyresource/get?product_id=' + id;  		
  	
        	//window.location.href = '/ads/modifyresource/get?ads_id=' + id;
    	},
        del: function( id ){
        	bootbox.setDefaults({
        		locale: "zh_CN"
        	});
        	bootbox.confirm("是否确定删除该条记录?", function(result) {
        		if(result){
        			$.getJSON("/product/delresource/delete?product_id="+id, function(data){
        				//location.reload(true);
        				document.location='/product/lists/get';
        			});
        		}
        	}); 
        }
    };

}();